package com.life.smile.utils;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * 分页 需要的实体类
 * @author xuq
 *2016-04-18
 */
public class Page {
	
	private int draw;//获取Datatables发送的参数 必要
	private int start;//开始记录条数
	private int length;//获取记录长度
	private int order_column;//排序列的索引
	private String order_dir;//升序 或者 降序 
	private String search_regex;//查询的 正则表达式
	private String search_value; //查询的 条件
	
	private Map<String,Object> pageMap=new HashMap<String,Object>();
	
	public Page(HttpServletRequest request,String[] columns){
		this.draw=Integer.parseInt(request.getParameter("draw"));
		this.start=Integer.parseInt(request.getParameter("start"));
		this.length=Integer.parseInt(request.getParameter("length"));
		this.order_column= Integer.parseInt(request.getParameter("order[0][column]")); //排序列的 索引
	    this.order_dir=request.getParameter("order[0][dir]");//排序规则
	    this.search_regex=request.getParameter("search[regex]");//查询的 正则表达式
		this.search_value= request.getParameter("search[value]");//查询条件
		
		this.pageMap.put("draw", this.draw);
		this.pageMap.put("start", this.start);
		this.pageMap.put("length", this.length);
		this.pageMap.put("order_column", this.order_column);
		this.pageMap.put("order_dir", this.order_dir);
		this.pageMap.put("search_regex", this.search_regex);
		this.pageMap.put("search_value", this.search_value);
		
		if(order_column != 0 ){//有排序列
			this.pageMap.put("order_column",columns[order_column-2]);
		}else{ this.pageMap.put("order_column",""); }
	}
	
	
	
	
	
	 



 





	/**
	 * @return the pageMap
	 */
	public Map<String, Object> getPageMap() {
		return pageMap;
	}















	/**
	 * @param pageMap the pageMap to set
	 */
	public void setPageMap(Map<String, Object> pageMap){
		this.pageMap = pageMap;
	}















	/**
	 * @return the draw
	 */
	public int getDraw() {
		return draw;
	}















	/**
	 * @param draw the draw to set
	 */
	public void setDraw(int draw) {
		this.draw = draw;
	}















	/**
	 * @return the search_regex
	 */
	public String getSearch_regex() {
		return search_regex;
	}





	/**
	 * @param search_regex the search_regex to set
	 */
	public void setSearch_regex(String search_regex) {
		this.search_regex = search_regex;
	}





	/**
	 * @return the start
	 */
	public int getStart() {
		return start;
	}
	/**
	 * @param start the start to set
	 */
	public void setStart(int start) {
		this.start = start;
	}
	/**
	 * @return the length
	 */
	public int getLength() {
		return length;
	}
	/**
	 * @param length the length to set
	 */
	public void setLength(int length) {
		this.length = length;
	}
 
	 
	 
	/**
	 * @return the order_column
	 */
	public int getOrder_column() {
		return order_column;
	}















	/**
	 * @param order_column the order_column to set
	 */
	public void setOrder_column(int order_column) {
		this.order_column = order_column;
	}















	/**
	 * @return the order_dir
	 */
	public String getOrder_dir() {
		return order_dir;
	}

	/**
	 * @param order_dir the order_dir to set
	 */
	public void setOrder_dir(String order_dir) {
		this.order_dir = order_dir;
	}

	/**
	 * @return the search_value
	 */
	public String getSearch_value() {
		return search_value;
	}
	/**
	 * @param search_value the search_value to set
	 */
	public void setSearch_value(String search_value) {
		this.search_value = search_value;
	}
	
}
